# 完成IHRM登陆，用于分析怎么进行封装
# 导包
import requests, app

# 1 发送IHRM登陆请求
response = requests.post(url=app.BASE_URL + "/api/sys/login",
                         headers=app.HEADERS,
                         json={"mobile": "13800000002",
                               "password": "123456"})
# 打印结果
print("URL为：", response.url)
print("登陆结果为：", response.json())

# 2 提取令牌
token = response.json().get("data")
app.HEADERS["Authorization"] = "Bearer " + token
print("保存到全局变量HEADERS为：", app.HEADERS)

# 3 查询员工列表
response = requests.get(url=app.BASE_URL + "/api/sys/user", params="page=1&size=10",
                        headers=app.HEADERS)
print("查询员工列表的结果为：", response.json())  # 打印查询员工的结果

# 4 添加员工
response = requests.post(url=app.BASE_URL + "/api/sys/user",
                         headers=app.HEADERS,
                         json={"username": "尼古拉斯特斯拉",
                               "mobile": "1834321644336",
                               "workNumber": "001",
                               "timeOfEntry": "2020-01-01",
                               "forOfEmployement": "1",
                               "departmentId": "9993",
                               "departmentName": "深圳18期测试部",
                               "correctionTime": "2020-01-01"})
print("添加员工结果为：", response.json())

# 5 提取员工ID
emp_id = response.json().get("data").get("id")
app.EMP_ID = emp_id # 把提取的ID保存到全局变量
print("提取的员工ID为：", app.EMP_ID)

# 6 查询员工
response = requests.get(url=app.BASE_URL + "/api/sys/user" + "/" + app.EMP_ID,
                        headers=app.HEADERS)
print("查询指定员工的结果为：", response.json())

# 7 修改员工
response = requests.put(url=app.BASE_URL + "/api/sys/user" + "/" + app.EMP_ID,
                        headers=app.HEADERS,
                        json={"username":"奥特曼"})
print("修改员工结果为：", response.json())

# 8 删除员工
response = requests.delete(url=app.BASE_URL + "/api/sys/user" + "/" + app.EMP_ID,
                           headers=app.HEADERS)
print("删除员工的结果：", response.json())





if __name__ == '__main__':
    a = {"k1": "v1", "k2": "v2"}
    # 需求，在a字典中添加一个k3,v3要怎么做？
    a["k3"] = "v3"
    print(a)

    # 调试字典.values()
    print(a.values())
    # 调试列表转元组
    print(tuple([1,2,3]))
    print(tuple(a.values()))